const express = require('express');
const router = express.Router();
const fileController = require('../controllers/fileController');
const { auth } = require('../middlewares/auth');
const { upload, handleUploadErrors } = require('../middlewares/upload');

// 所有路由都需要认证
router.use(auth);

// POST /api/files/upload - 上传文件
router.post(
  '/upload', 
  upload.single('file'), // 'file'是前端上传表单中文件字段的名称
  handleUploadErrors, 
  fileController.uploadFile
);

// GET /api/files - 获取文件列表
router.get('/', fileController.getFiles);

// GET /api/files/:id - 获取单个文件信息
router.get('/:id', fileController.getFile);

// GET /api/files/:id/download - 下载文件
router.get('/:id/download', fileController.downloadFile);

// DELETE /api/files/:id - 删除文件
router.delete('/:id', fileController.deleteFile);

module.exports = router; 